package com.explorex.infra.puma.gateway.netty.rrmp.codec;

import lombok.extern.slf4j.Slf4j;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

/**
 * @author: JacceYang
 * @createTime: 2022/09/07 20:06
 * @description:
 */
@Slf4j
public class CipherUtil {

    public static byte[] getBodyCheckValue(byte[] body) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] theDigest = md.digest(body);
            if (theDigest != null) {
                return Arrays.copyOfRange(theDigest, 13, 16);
            }
        } catch (NoSuchAlgorithmException e) {
            log.error("{} getBodyCheckValue NoSuchAlgorithmException", body, e);
        } catch (Exception e) {
            log.error("{} getBodyCheckValue error: ", e);
        }
        return null;
    }
}
